#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 50010;
const int M = 1e9 + 7;

struct Edge
{
    int to, next;
} e[N << 1];

int head[N], idx = 1;

void add_edge(int u, int v)
{
    e[idx].to = v;
    e[idx].next = head[u];
    head[u] = idx++;
}
void clear_graph()
{
    memset(head, -1, sizeof(head));
    memset(e, 0, sizeof(e));
    idx = 1;
}

int t, n;
int r[N][6];

int get_max(int u, int v)
{
    int cnt = 0;
    for (int i = 1; i <= 5; i++)
    {
        if (r[u][i] < r[v][i])
            cnt++;
    }

    if (cnt >= 3)
        return u; // u排名靠前的多，u更大
    else
        return v;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> t;
    while (t--)
    {
        cin >> n;
        memset(r, 0, sizeof(r));
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= 5; j++)
                cin >> r[i][j];

        if (n == 1)
        {
            cout << 1 << endl;
            continue;
        }

        int m = 1;
        for (int i = 2; i <= n; i++)
            m = get_max(i, m);

        int m2 = n;
        for (int i = n - 1; i >= 1; i--)
            m2 = get_max(i, m2);


        cout << (m == m2 ? m : -1) << endl;
    }
    return 0;
}